package cn.tedu.spring.boot.quartz.config;

import cn.tedu.spring.boot.quartz.job.HelloJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {
    //job需要通过jobDetail对象封装，定义JobDetail并交给spring容器管理
    @Bean
    public JobDetail showTime(){
        return JobBuilder.newJob(HelloJob.class)
                .withIdentity("showTime")
                .storeDurably()
                .build();
    }
    //定义一个触发器
    @Bean
    public Trigger showTimeTrigger(){
        CronScheduleBuilder cron =
                CronScheduleBuilder.cronSchedule("0/10 * * 23 8 ?");
        return TriggerBuilder.newTrigger()
                .forJob(showTime())
                .withIdentity("showTimeTrigger")
                .withSchedule(cron)
                .build();
    }
}
